#-*-coding:UTF-8-*-

import logging

from tornado.log import gen_log, access_log, app_log

from .config import get_property

LOG_LEVELS = {'CRITICAL': logging.CRITICAL, 'ERROR': logging.ERROR, 'WARNING': logging.WARNING,
             'INFO': logging.INFO, 'DEBUG': logging.DEBUG, 'NOTSET': logging.NOTSET}

logger = app_log

def set_log_level():
    app_log_level = get_property('app_logger_level')
    access_logger_level = get_property('access_logger_level')
    gen_logger_level = get_property('gen_logger_level')
    if app_log_level and LOG_LEVELS.has_key(app_log_level):
        app_log.setLevel(LOG_LEVELS[app_log_level])
    if access_logger_level and LOG_LEVELS.has_key(access_logger_level):
        access_log.setLevel(LOG_LEVELS[access_logger_level])
    if gen_logger_level and LOG_LEVELS.has_key(gen_logger_level):
        gen_log.setLevel(LOG_LEVELS[gen_logger_level])
    #print_logger_info()


def print_logger_info():
    print('----------debug: handlers of root    = %s'%logging.getLogger().handlers)
    print('----------debug: app_log.handlers    = %s'%logging.getLogger('tornado.application').handlers)
    print('----------debug: access_log.handlers = %s'%logging.getLogger('tornado.access').handlers)
    print('----------debug: gen_log.handlers    = %s'%logging.getLogger('tornado.general').handlers)
    print('----------debug: debug level of root        = %s'%logging.getLogger().getEffectiveLevel())
    print('----------debug: debug level of application = %s'%logging.getLogger('tornado.application').getEffectiveLevel())
    print('----------debug: debug level of access      = %s'%logging.getLogger('tornado.access').getEffectiveLevel())
    print('----------debug: debug level of general     = %s'%logging.getLogger('tornado.general').getEffectiveLevel())
    print('----------debug: debug level CRITICAL=50, ERROR=40, WARNING=30, INFO=20, DEBUG=10, NOTSET=0')


#set_log_level()
